package com.example.dell.basicapplication;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.example.dell.interfacepack.OnFinishListener;
import com.example.dell.utils.AppManager;
import com.example.dell.utils.PhoneTypeUtil;
import com.example.dell.weigit.CercleProgressView;

public class SplashActivity extends AppCompatActivity {

    private CercleProgressView mCerCle;
    private String             markIn = "";
    private TextView           mSplashText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        AppManager.getInstance().addActivity(SplashActivity.this);

        //修改手机栏上标题文字的颜色
//        Activity parent = SplashActivity.this;
//        PhoneTypeUtil.setLightStatusBar(parent, true);

        mCerCle = (CercleProgressView) findViewById(R.id.cercleprogressview);
        mSplashText = (TextView) findViewById(R.id.splash_text);

        mCerCle.startDownTime(3000, new OnFinishListener() {
            @Override
            public void onFinish(String time) {
                if (TextUtils.equals("0", time)) {
                    mSplashText.setText("跳过");
                } else if (!TextUtils.equals(markIn, time) && null != time) {
                    markIn = time;
                    mSplashText.setText(time + "");
                } else if (null == time) {
                    Activity activity = AppManager.getInstance().getActivity(SplashActivity.class);
                    if (activity!=null) {
                        startActivity(new Intent(SplashActivity.this, MainActivity.class));
                        AppManager.getInstance().finishActivity(activity);
                    }
                }
            }
        });

        mSplashText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Activity activity = AppManager.getInstance().getActivity(SplashActivity.class);
                if (activity!=null) {
                    startActivity(new Intent(SplashActivity.this, MainActivity.class));
                    AppManager.getInstance().finishActivity(activity);
                }
            }
        });

        //如果从html5跳过来的
        Intent intent = getIntent();
        String action = intent.getAction();
        String type= null;
        String id = null;
        if (Intent.ACTION_VIEW.equals(action)) {
            Uri uri = intent.getData();
            if (uri != null) {
                type = uri.getQueryParameter("type");
                id = uri.getQueryParameter("id ");
            }
        }

    }


}
